import { deleteSetmealAPI, fetchSetmealListAPI, updateSetmealStatusAPI } from '@/api/setmalAPI'
import { updateDishStatusAPI } from '@/api/dishAPI'

const actions = {
  /* 获取套餐列表的action */
  async fetchSetmealListAction(context, pageParams) {
    const { data } = await fetchSetmealListAPI(pageParams)
    context.commit('setSetmealList', data)
  },

  /* 删除套餐的action */
  async deleteSetmealAction(context, ids) {
    await deleteSetmealAPI(ids)
    return '删除套餐成功'
  },

  /* 起售和停售套餐的action */
  async updateSetmealStatusAction(context, { status, id }) {
    await updateSetmealStatusAPI(status, id)
    return status === 1 ? '启售成功' : '停售成功'
  },
}

const mutations = {
  /* 设置套餐列表的mutation */
  setSetmealList(state, { total, records }) {
    state.records = records
    state.total = total
  }
}

const state = {
  records: [],
  total: 0
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
